package hw1;

public class MyStatic {

    public int idex;//
    public Object [] arr;


    public MyStatic() {
    }

    public MyStatic(int ini) {
        this.arr = new Object[ini];
        //System.out.println(arr.length);

    }
    public void push (Object o) {


        if(arr.length ==0) {
            System.out.println("栈的长度为0");
        }
        else if (idex == arr.length) {
            System.out.println("栈已经满了,不能在继续压栈了");
        } else {
            arr[idex++] =o;
            System.out.println("压栈成功！！");
        }

    }
    public String jump () {
       if(idex == arr.length) {
           idex --;
       }
        if (idex == 0) {
            return "弹栈失败，栈已经空了!";
        }
        arr[idex--] = 0;
        return "弹栈成功！";
    }
    public void print() {
        if (idex == 0) {
            System.out.println("栈中不存在任何元素");
        } else {
            System.out.print("栈中现有元素[");
            for (int i = 0;i < arr.length;i++) {
                System.out.print(arr[i]);
                if((i+1) != arr.length) {
                    System.out.print(",");
                }
            }
            System.out.print("]");
            System.out.println();

        }

    }
}
